<script type="text/javascript" src="/ueditor/ueditor.config.js"></script>
<!-- 编辑器源码文件 -->
<script type="text/javascript" src="/ueditor/ueditor.all.js"></script>




<script src="/bootstrap-fileinput/js/fileinput.min.js"></script>
<link href="/bootstrap-fileinput/css/fileinput.min.css" rel="stylesheet"/>

<form role="form" method="post">
    <div class="form-group">
        <label>名称</label>
        <input class="form-control" name="name" value="<%= data.name %>">

    </div>

    <div class="form-group">
        <label>分类</label>
        <select name="catid">


        </select>
    </div>
    <div class="form-group">
        <label>图片</label>
        <input type="file" id="image" multiple>
        <input type="text" name="image" value="<%= data.image %>" class="" >
    </div>
    <div class="form-group">
        <label>内容</label>
        <textarea name="content" id="content" style="height:300px"><%- data.content %></textarea>
    </div>

    <div class="form-group">
        <label>排序</label>
        <input type="number" name="sort" value="<%= data.sort||100 %>"/>
    </div>
    <div class="form-group">
        <label>作者</label>
        <input class="form-control" name="author" value="<%= data.author %>" required="">

    </div>

    <button class="btn btn-primary" type="button">提交</button>
    <button class="btn btn-success" type="reset">重置</button>
</form>

<script type="text/javascript">
    var filearr = [];
    var catid = '<%= data.catid %>';
    var ue = UE.getEditor('content');
    $('#image').fileinput({
        uploadUrl: '/upload'
        //allowedFileExtensions : ['jpg', 'png','gif']
    }).on('fileuploaded', function (event, data, previewId, index) {
        var form = data.form, files = data.files, extra = data.extra,
                response = data.response, reader = data.reader;
        filearr.push(response[0].url);
        console.log(filearr.join(","));
        $("input[name=image]").val(filearr.join(","));
    });

    $(function () {

        $.ajax({
            url: '/admin/articleCat?ajax=1',

            success: function (res) {

                var html = '<option value="">请选择</option>';
                var checked = "";

                for (var i = 0; i < res.length; i++) {

                    if(catid==res[i]._id)
                        checked = 'selected="selected"';
                    html += '<option value="' + res[i]._id + '" '+checked+'>' + res[i].name;
                }

                $("select[name=catid]").html(html);

            }
        });

        $("*[type=button]").click(function(){
            var content = ue.getContent().replace(/:/g,"\:");

            ue.setContent(content);
           $("form").submit();
        })

    })
</script>